package com.example.qundui.learndemo.lvtest;

import android.support.v7.widget.RecyclerView;

/**
 * Created by qundui on 2017/5/2.
 */


import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;


import com.example.qundui.learndemo.R;
import com.squareup.picasso.Picasso;

import java.util.List;

/**
 * Created by qundui on 2017/4/30.
 */

public class MyAdapter extends RecyclerView.Adapter<MyAdapter.VH> {
    private List<String> strings;
    private Context ctx;
    private String[] url;

    public MyAdapter(Context ctx, String[] url) {
        this.ctx = ctx;
        this.url = url;
    }

    public MyAdapter(Context ctx, List<String> strings) {
        this.ctx=ctx;
        this.strings=strings;
    }

    @Override
    public VH onCreateViewHolder(ViewGroup parent, int viewType) {
        return new VH(LayoutInflater.from(ctx).inflate(R.layout.rv_items,parent,false));
    }

    @Override
    public void onBindViewHolder(VH holder, int position) {
        Picasso.with(ctx).load(strings.get(position)).into(holder.iv);

    }
    @Override
    public int getItemCount() {
        return strings.size();
    }
    public class VH extends RecyclerView.ViewHolder {
        private ImageView iv;
        public VH(View itemView) {
            super(itemView);
            iv= (ImageView) itemView.findViewById(R.id.iv);
        }
    }
}
